package leetcode

/**
Given a binary sort.getArray, find the maximum number of consecutive 1s in this sort.getArray.

Example 1:
Input: [1,1,0,1,1,1]
Output: 3
Explanation: The first two digits or the last three digits are consecutive 1s.
The maximum number of consecutive 1s is 3.
 *
 *
 */
fun main(args: Array<String>) {

    println(findMaxConsecutiveOnes(intArrayOf(0)))
}

fun findMaxConsecutiveOnes(nums: IntArray): Int {

    var i = 0
    var counter = 0
    var max = 0
    while (i < nums.size) {
        if (nums[i] == 1) {
            counter++
            max = Math.max(counter, max)
        } else {
            counter = 0
        }
        i++
    }

    return max
}